<template>
  <view class="things">
    <view class="top">
      <img src="../images/hot.png" alt="" class="img" />
      <view class="text">热门商品</view>
    </view>
    <view class="main">
      <view
        class="box"
        v-for="(item, index) in hotList"
        :key="index"
        @tap="jumpPage(item)"
      >
        <img :src="item.cover_image" alt="" class="img" />
        <!-- 限时首抽 -->
        <!-- <view class="first_chou">
          <img
            :src="
              $IMG_URL +
              '/uploads/20230609/3321e049787affd3f7ed4257e8525e54.png'
            "
            mode="heightFix"
          />
          <view class="right">
            <view class="text_end">距离结束</view>
            <u-count-down
              :timestamp="timestamp"
              separator-color="#FC502B"
              bg-color="#FC502B"
              color="#fff"
              separator-size="24"
              font-size="24"
            ></u-count-down>
          </view>
        </view> -->
        <view class="text">{{ item.title }}</view>
        <view class="biaoqian">
          <img
            src="../images/yfs.png"
            alt=""
            class="img2"
            v-if="item.activity_type == '1'"
            mode="heightFix"
          />
          <img
            src="../images/fd.png"
            alt=""
            class="img2"
            v-if="item.activity_type == '2'"
            mode="heightFix"
          />
        </view>
        <view class="bd">
          <img
            :src="
              $IMG_URL +
              '/uploads/20230428/a59867fdb06a2fad2c4cb16e65513a65.jpg'
            "
            alt=""
            class="bq_img"
          />
          <view class="qujian">{{ item.min }}~{{ item.max }}元</view>
        </view>
        <view class="price">
          <view class="new_price">
            <view class="bq">￥</view>
            <view class="jiage">{{ item.single_price }}</view>
            <!-- <view class="first">首抽价</view> -->
            <img src="../images/scPrice.png" alt="" mode="heightFix" />
          </view>
          <text class="old_price">{{ item.original_price }}</text>
        </view>
        <view class="xiaoliang">月销{{ item.sale_total }}笔</view>
      </view>
    </view>
  </view>
</template>
<script>
export default {
  // 建议 创建每个组件时 都添加name属性 标识组件名称
  name: 'indexThings',
  components: {},
  props: {
    page: {
      type: [Number, String],
      default: 1,
    },
  },
  data() {
    return {
      hotList: [],
      rows: 10,
      timestamp: 100,
    };
  },
  // 计算属性 适配者模式
  computed: {},
  // 数据监听
  watch: {
    page(val) {
      this.getHotList();
    },
  },
  mounted() {
    this.getHotList();
  },
  onLoad() {},
  // 监听页面显示。页面每次出现在屏幕上都触发 包括从下级页面点返回露出当前页面
  onShow() {},
  // 监听页面初次渲染完成 注意如果渲染速度快，会在页面进入动画完成前触发
  onReady() {},
  // 监听页面隐藏
  onHide() {},
  // 监听页面卸载
  onUnload() {},
  methods: {
    getHotList() {
      return new Promise((resolve, reject) => {
        this.$http('v1.activitysList', {
          tag: '1',
          page: this.page,
          rows: this.rows,
        }).then((res) => {
          if (res.code === 1) {
            let { data } = res;
            if (data.list.length == this.rows) {
              this.hotList = [...this.hotList, ...data.list];
            } else {
              this.hotList = [...this.hotList, ...data.list];
              this.$emit('finish');
            }

            resolve(res.data);
          } else {
            reject();
          }
        });
      });
    },
    jumpPage(e) {
      switch (e.activity_type) {
        case '1':
          uni.navigateTo({
            url: `/pages/rewardGoods/portrait/index?id=${e.id}`,
          });

          break;
        case '2':
          uni.navigateTo({
            url: `/pages/fukubukuro/extract/extract?id=${e.id}`,
          });
          break;
      }
    },
  },
  /** ---------- */
  // 监听窗口尺寸变化 App、微信小程序、快手小程序
  //onResize() {},
  // 监听用户下拉动作，一般用于下拉刷新
  //onPullDownRefresh() {},
  // 页面滚动到底部的事件（不是scroll-view滚到底），常用于下拉下一页数据
  //点击 tab 时触发，参数为Object 微信小程序、QQ小程序、支付宝小程序、百度小程序、H5、App、快手小程序、京东小程序
  //onTabItemTap() {},
  //用户点击右上角分享 微信小程序、QQ小程序、支付宝小程序、字节小程序、飞书小程序、快手小程序、京东小程序
  //onShareAppMessage() {},
  //监听页面滚动 nvue暂不支持
  //onPageScroll() {},
  //监听原生标题栏按钮点击事件 App、H5
  //onNavigationBarButtonTap() {},
  /** 监听页面返回
   * 返回 event = {from:backbutton、 navigateBack} ，backbutton 表示来源是左上角返回按钮或 android 返回键
   * navigateBack表示来源是 uni.navigateBack ；
   * 支付宝小程序只有真机能触发，只能监听非navigateBack引起的返回，不可阻止默认行为。
   * app、H5、支付宝小程序
   */
  //onBackPress() {},
  // 监听原生标题栏搜索输入框输入内容变化事件 App、H5
  //onNavigationBarSearchInputChanged() {},
  // 监听原生标题栏搜索输入框搜索事件，用户点击软键盘上的“搜索”按钮时触发。App、H5
  //onNavigationBarSearchInputConfirmed() {},
  // 监听原生标题栏搜索输入框点击事件（pages.json 中的 searchInput 配置 disabled 为 true 时才会触发）App、H5
  //onNavigationBarSearchInputClicked() {},
  // 监听用户点击右上角转发到朋友圈 微信小程序
  //onShareTimeline() {},
  // 监听用户点击右上角收藏 微信小程序、QQ小程序
  //onAddToFavorites() {},
};
</script>
<style lang="scss" scoped>
.things {
  padding: 22rpx 30rpx 20rpx 30rpx;
  width: 100%;
  .top {
    width: 100%;
    height: 61rpx;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    .img {
      width: 60rpx;
      height: 60rpx;
    }
    .text {
      font-size: 39rpx;
      color: #000;
      font-weight: bold;
      line-height: 61rpx;
      margin-left: 10rpx;
    }
  }
  .main {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    justify-content: space-between;
    .box {
      width: 48%;
      display: flex;
      flex-direction: column;
      margin-top: 29rpx;
      background-color: #fff;
      border-radius: 30rpx;
      position: relative;
      .img {
        border-radius: 30rpx 30rpx 0 0;
        width: 100%;
        height: 324rpx;
      }
      .first_chou {
        position: absolute;
        top: 274rpx;
        left: 0;
        width: 100%;
        height: 50rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 5rpx;
        box-sizing: border-box;
        background: rgba(255, 255, 255, 0.35);
        backdrop-filter: blur(2px);
        img {
          height: 42rpx;
          margin-left: 6rpx;
        }
        .right {
          height: 50rpx;
          display: flex;
          align-items: center;
          /deep/ u-count-down {
            line-height: 1;
          }
          .text_end {
            display: inline-block;
            font-size: 16rpx;
            font-family: PingFang SC-Regular, PingFang SC;
            font-weight: 400;
            color: #030021;
            margin-right: 10rpx;
          }
        }
      }
      .text {
        width: 314rpx;
        font-size: 28rpx;
        margin-left: 14rpx;
        margin-top: 11rpx;
        color: #000;
        white-space: nowrap;
        // word-break: break-all;/*属性规定自动换行的处理方法。normal(使用浏览器默认的换行规则。),break-all(允许在单词内换行。),keep-all(只能在半角空格或连字符处换行。)*/
        text-overflow: ellipsis;
        // display: -webkit-box; /** 对象作为伸缩盒子模型显示 **/
        // -webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/
        // -webkit-line-clamp: 1; /** 显示的行数 **/
        overflow: hidden; /** 隐藏超出的内容 **/
        // height: 65rpx;
        line-height: 32rpx;
        font-family: PingFang SC-Heavy, PingFang SC;
        font-weight: 800;
      }
      .biaoqian {
        display: flex;
        justify-content: flex-start;
        margin-top: 10rpx;
        margin-bottom: 10rpx;
        margin-left: 14rpx;
        .img2 {
          height: 28rpx;
        }
      }
      .bd {
        position: relative;
        margin-left: 14rpx;
        margin-right: 14rpx;
        width: 303rpx;
        height: 49rpx;
        .bq_img {
          width: 322rpx;
          height: 50rpx;
        }
        .qujian {
          position: absolute;
          display: inline-block;
          width: 152rpx;
          height: 50rpx;
          line-height: 50rpx;
          font-size: 20rpx;
          font-family: PingFang SC-Bold, PingFang SC;
          font-weight: 400;
          color: #df3d3d;
          right: 0;
          top: 0;
          text-align: center;
        }
      }
      .price {
        display: flex;
        justify-content: space-between;
        margin-left: 14rpx;
        margin-right: 14rpx;
        align-items: flex-end;
        margin-top: 6rpx;
        .new_price {
          .bq {
            display: inline;
            font-size: 24rpx;
            font-family: PingFang SC-Bold, PingFang SC;
            font-display: swap;
            font-weight: bold;
            color: #fc3d18;
          }
          .jiage {
            color: #fc3d18;
            display: inline;
            font-size: 35rpx;
            font-family: DIN-Bold;
            font-display: swap;
            font-weight: bold;
          }
          img {
            height: 27rpx;
          }
          .first {
            font-size: 22rpx;
            color: #fc3d18;
            display: inline;
            font-family: Bahnschrift-Bold, Bahnschrift;
            font-weight: bold;
            margin-left: 2rpx;
          }
        }
        .old_price {
          text-decoration: line-through;
          font-size: 18rpx;
          font-family: DIN-Light;
          font-weight: 400;
          color: #a6a6bc;
        }
      }
      .xiaoliang {
        font-size: 20rpx;
        font-family: PingFang SC-Bold, PingFang SC;
        font-weight: bold;
        color: #8f8f8f;
        margin-top: 6rpx;
        margin-left: 16rpx;
        margin-bottom: 16rpx;
      }
    }
  }
}
</style>
